package com.eastcom.groovy.provider

import org.springframework.beans.factory.BeanFactory
import org.springframework.beans.factory.support.BeanDefinitionRegistry
import org.springframework.beans.factory.support.DefaultListableBeanFactory
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader
import org.springframework.core.io.FileSystemResource

/**
 * 不同业务之间不同的bean
 * */
class DynamicBeanDomianProvider {
	public static BeanFactory beanFactory
	private static XmlBeanDefinitionReader reader
	public static boolean init(){
		BeanDefinitionRegistry reg = new DefaultListableBeanFactory();
		reader = new XmlBeanDefinitionReader(reg);

		//		reader.loadBeanDefinitions(new FileSystemResource("E:\\workspace2\\GreatDataCollector\\config\\db_simplesql_collector\\dao_config.xml"));

		beanFactory = (BeanFactory)reg;
	}

	public static boolean loadXmlConfigFile(String[] files){
		files.each {
			reader.loadBeanDefinitions(new FileSystemResource(it));
		}
		//		reader.loadBeanDefinitions(new FileSystemResource("E:\\workspace2\\GreatDataCollector\\config\\db_simplesql_collector\\dao_config.xml"));
	}

	public static boolean loadXmlConfigFile(String file){
		reader.loadBeanDefinitions(new FileSystemResource(file));
		//		reader.loadBeanDefinitions(new FileSystemResource("E:\\workspace2\\GreatDataCollector\\config\\db_simplesql_collector\\dao_config.xml"));
	}
	public static Object getBean(String beanName){
		return beanFactory.getBean(beanName)
	}
}
